package day12;
//哈希码
public class demo10 {
    public static void main(String[] args) {
        System.out.println("第一类：对象类,根据地址计算");
        demo10 d1=new demo10();
        demo10 d2=new demo10();
        demo10 d3=d1;
        System.out.println("d1"+d1.hashCode());
        System.out.println("d2"+d2.hashCode());
        System.out.println("d3"+d3.hashCode());

        System.out.println("第二类：基本类型封装类，就是对应数值");
        Integer num1=100;
        Long num2=1000l;
        Integer num3=new Integer(10000);
        System.out.println("num1:"+num1.hashCode() );
        System.out.println("num2:"+num2.hashCode() );
        System.out.println("num3:"+num3.hashCode() );

        System.out.println("第三类：String类，根据字符串内容计算");
        String str1="java";
        String str2=new String("java");
        //容易出现hash冲突：hashCode相同，但是值不同，属于hash冲突
        String str3="种地";
        String str4="通话";
        System.out.println("str1:"+str1.hashCode());
        System.out.println("str2:"+str2.hashCode());
        //str3和str4就属于hash冲突
        System.out.println("str3:"+str3.hashCode());
        System.out.println("str4:"+str4.hashCode());
    }
}
